package com.coderly.onlinegallerysharingplatform.enums;

import lombok.Getter;

/**
 * 用户角色枚举
 */
import java.util.HashMap;
import java.util.Map;

@Getter
public enum UserRoleEnum {

    USER("用户", "user"),
    ADMIN("管理员", "admin");

    private final String key;
    private final String value;

    private static final Map<String, UserRoleEnum> ENUM_MAP = new HashMap<>();

    static {
        for (UserRoleEnum userRoleEnum : values()) {
            ENUM_MAP.put(userRoleEnum.value, userRoleEnum);
        }
    }

    UserRoleEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    /**
     * 根据枚举值获取枚举对象
     * @param value 枚举值
     * @return 对应的枚举对象，如果找不到则返回 null
     */
    public static UserRoleEnum getEnumByValue(String value) {
        if (value == null || value.isEmpty()) {
            return null;
        }
        return ENUM_MAP.get(value);
    }
}
